package com.yztstudy.Controller;

import com.yztstudy.Service.CategoryService;
import com.yztstudy.entity.Category;
import com.yztstudy.param.PageParam;
import com.yztstudy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员调用分类服务的表示层
 */

@RestController
@RequestMapping("/category")
public class AdminCategoryController {

    @Autowired
    private CategoryService categoryService;


    /**
     * TODO 分页查询种类
     * @param pageParam 分页参数
     * @return
     */
    @GetMapping("/admin/list")
    public R listPage(@RequestBody PageParam pageParam)
    {
        return categoryService.listPage(pageParam);
    }


    /**
     * TODO 新增分类
     * @param category 分类对象
     * @return
     */
    @PostMapping("/admin/save")
    public R saveCategory(@RequestBody Category category)
    {
        return categoryService.saveCategory(category);
    }


    /**
     * TODO 删除类别
     * @param categoryId 类别ID
     * @return
     */
    @PostMapping("/admin/remove")
    public R adminRemove(@RequestBody Integer categoryId)
    {
        return categoryService.adminRemove(categoryId);
    }


    /**
     * TODO 更新类别
     * @param category 类别对象
     * @return
     */
    @PostMapping("/admin/update")
    public R adminUpdate(@RequestBody Category category)
    {
        return categoryService.adminUpdate(category);
    }
}
